package table_objects;

import org.joda.time.DateTime;
import org.joda.time.Period;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Autor: Daniel Michalski
 * Data: 23.06.13
 */

public class DzienPracy implements Serializable {
    private DateTime startTime;
    private DateTime endTime;
    private Date data;
    private int workedHours;
    private int workedMinutes;
    private String howManyWorkedHoursString;


    public DzienPracy(DateTime startTime, DateTime endTime, Date date) {
        this.startTime = startTime;
        this.endTime = endTime;
        this.data = date;

        obliczIleGodzinPrzepracowanych();
    }

    private void obliczIleGodzinPrzepracowanych() {
        Period period = new Period(startTime, endTime);
        workedHours = period.getHours();
        workedMinutes = period.getMinutes();
        howManyWorkedHoursString = workedHours + " godz. " + workedMinutes + " min.";
    }
    public int getWorkedMinutes() {
        return workedMinutes;
    }

    public int getWorkedHours() {
        return workedHours;
    }

    public String getDateString() {
        DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
        return df.format(data);
    }

    public String getStartHourString() {
        String dodatek = "";

        if (startTime.minuteOfHour().get() < 10)
            dodatek = "0";

        return startTime.getHourOfDay() + ":" + dodatek + startTime.minuteOfHour().get();
    }

    public String getEndHourString() {
        String dodatek = "";

        if (endTime.getMinuteOfHour() < 10)
            dodatek = "0";

        return endTime.getHourOfDay() + ":" + dodatek + endTime.minuteOfHour().get();
    }

    public String getHowManyWorkedHoursString() {
        return howManyWorkedHoursString;
    }

    public Date getData() {
        return data;
    }

    @Override
    public String toString() {
        return "DzienPracy{" +
                "data=" + data +
                ", workedHours=" + workedHours +
                ", workedMinutes=" + workedMinutes +
                ", howManyWorkedHoursString='" + howManyWorkedHoursString + '\'' +
                '}';
    }
}
